# -*- encoding: utf-8 -*-
"""
@Author: cuiyonghua
@CreateDate: 2020/08/30 10:11 上午
@File: 自定义响应状态码.py
@Description: 
"""
from fastapi import FastAPI
from starlette import status

app = FastAPI()


# 201
@app.get("/201/", status_code=status.HTTP_201_CREATED)
async def item201():
    return {"httpStatus": 201}


# 302
@app.get("/302/", status_code=status.HTTP_302_FOUND)
async def items302():
    return {"httpStatus": 302, "message": '请求被禁止'}


# 404
@app.get("/404/", status_code=status.HTTP_404_NOT_FOUND)
async def items404():
    return {"httpStatus": 404}


# 500
@app.get("/500/", status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
async def items500():
    return {"httpStatus": 500}


if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)
